Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to format lists with paginated results including totalCount #80

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

DaKaZ
Copy link

@DaKaZ DaKaZ commented May 29, 2019

In our use of objection-graphql we were having a hard time doing pagination correctly. The main reason is that we did not receive a totalCount of records available which made layout of the results difficult.

With this PR, you can build your schema passing true into the build function like this:

const rootSchema = builder()
  .allModels(allModels);
  .build(true);

and once that is constructed, you can query like this:

query fetchUsers {
  users(limit: 4, offset: 6) {
    collection {
      id
      name
      handle
      location
      pets {
        name
        type
      }
    }
    totalCount
  } 
}

and the totalCount is returned along with a list of the users.

Michael S. Kazmier added 2 commits May 29, 2019 12:54
@DaKaZ
Copy link
Author

DaKaZ commented Sep 13, 2019

@nasushkov any chance to get a review/comments on this PR?

@lookfirst
Copy link

@DaKaZ This looks nice except that I wouldn't do it with a naked boolean to build(). I'd add .paginated() or at least pass in an object into build(), which could take an argument, the name of the 'collection' and 'totalCount' properties in case someone wanted to use something else.

@DaKaZ
Copy link
Author

DaKaZ commented Dec 18, 2019

@lookfirst sorry for the incredibly slow turn around! I just revisited this and had an AH HA moment.
I don't know why I did not before, but I move the paginated option into the setBuilderOptions so you can now do this:

const graphQlSchema = graphQlBuilder()
  .model(Movie)
  .model(Person)
  .model(Review)
  .setBuilderOptions({ paginated: true })
  .build(); 

What do you think? I did not add the ability to change the collection or totalCount fields, but that could be subsequent PR if someone really wanted/needed that.

@lookfirst
Copy link

@DaKaZ 🤷‍♂ ... I'm super sorry but I moved onto using type-graphql and mikro... pretty much the ideal combination.

@DaKaZ
Copy link
Author

DaKaZ commented Dec 19, 2019

@koskimas or @nasushkov - any chance on of you could take a quick look at this and perhaps some of the other PRs that are outstanding?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants